home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Snippets / Stuart's Tech Notes / StUU / Sources / DropShell.c < prev    next >
Text File  |  1996-03-27  |  7KB  |  285 lines

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Author    Description
  23. **    ---------    ------    ---------------------------------------------
  24. **    23 Jun    94    LDR        Implemented support for disk insertion events
  25. **    02 Feb    94    LDR        Updated for Final SDK & CodeWarrior a2
  26. **                        Removed the ResumeProc as per new Apple recommendations
  27. **    11 Dec 93    SCS        Universal Headers/UPPs (Phoenix 68k/PPC & PPCC)
  28. **                        Skipped System 6 compatible rev of DropShell source
  29. **    09 Dec 91    LDR        Added support for new "Select File…" menu item
  30. **                        Quit now sends AEVT to self to be politically correct
  31. **                        Added support for the new gSplashScreen
  32. **    24 Nov 91    LDR        Added support for the Apple Menu (duh!)
  33. **    29 Oct 91    SCS        Changes for THINK C 5
  34. **    28 Oct 91    LDR        Officially renamed DropShell (from QuickShell)
  35. **                        Added a bunch of comments for clarification
  36. **    06 Oct 91    MTC        Converted to MPW C
  37. **    09 Apr 91    LDR        Added to Projector
  38. **
  39. ******************************************************************************/
  40.  
  41. #ifndef __MWERKS__
  42. #include <Desk.h>
  43. #include <Dialogs.h>
  44. #include <Errors.h>
  45. #include <Files.h>
  46. #include <Fonts.h>
  47. #include <Memory.h>
  48. #include <Menus.h>
  49. #include <StandardFile.h>
  50. #include <TextEdit.h>
  51. #include <Types.h>
  52. #include <Windows.h>
  53. #endif
  54.  
  55. #include "DSGlobals.h"
  56. #include "DSUserProcs.h"
  57. #include "DSAppleEvents.h"
  58.  
  59. #include "DropShell.h"
  60.  
  61.  
  62.  
  63. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  64. EventRecord    gEvent;
  65. MenuHandle    gAppleMenu, gFileMenu;
  66. WindowPtr    gSplashScreen;
  67.  
  68. #ifdef MPW
  69. extern void _DataInit();    
  70. #endif
  71.  
  72.  
  73. #pragma segment Initialize
  74. void InitToolbox (void) 
  75. {
  76.  
  77. #ifdef MPW
  78.     UnloadSeg ((Ptr) _DataInit );
  79. #endif
  80.  
  81.     MaxApplZone();
  82.     InitGraf ( &qd.thePort );
  83.     InitFonts ();
  84.     InitWindows ();
  85.     InitMenus ();
  86.     TEInit ();
  87.     InitDialogs (0);        // use of ResumeProcs no longer approved by Apple
  88.     InitCursor ();
  89.     FlushEvents ( everyEvent, 0 );
  90.     
  91.     // how about some memory fun! Two should be enough!
  92.     MoreMasters ();
  93.     MoreMasters ();
  94.     }
  95.  
  96. /*
  97.     Let's setup those global variables that the DropShell uses.
  98.     
  99.     If you add any globals for your own use,
  100.     init them in the InitUserGlobals routine in DSUserProcs.c
  101. */
  102. #pragma segment Initialize
  103. Boolean InitGlobals (void) 
  104. {
  105.     long aLong;
  106.  
  107.     gDone            = false;
  108.     gOApped            = false;    // probably not since users are supposed to DROP things!
  109.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  110.     gSplashScreen    = NULL;
  111.  
  112.     return(InitUserGlobals());    // call the user proc
  113. }
  114.  
  115. /*
  116.     Again, nothing fancy.  Just setting up the menus.
  117.     
  118.     If you add any menus to your DropBox - insert them here!
  119. */
  120. #pragma segment Initialize
  121. void SetUpMenus (void) {
  122.  
  123.     gAppleMenu = GetMenu ( kAppleNum );
  124.     AddResMenu ( gAppleMenu, 'DRVR' );
  125.     InsertMenu ( gAppleMenu, 0 );
  126.  
  127.     gFileMenu = GetMenu ( kFileNum );
  128.     InsertMenu ( gFileMenu, 0 );
  129.     DrawMenuBar ();
  130. }
  131.  
  132. /*
  133.     This routine is called during startup to display a splash screen.
  134.     
  135.     This was recommend by the Blue Team HI person, John Sullivan, who
  136.     feels that all apps should display something so that users can easily
  137.     tell what is running, and be able to switch by clicking.  Thanks John!
  138. */
  139. #pragma segment Initialize
  140. void InstallSplashScreen(void) 
  141. {
  142.     #define windowPicID    128
  143.  
  144.     PicHandle    picH;
  145.  
  146.     if (!gSplashScreen && 0) {  // show the splash screen window
  147.         picH = GetPicture(windowPicID);
  148.         if (picH) {
  149.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  150.             if (gSplashScreen) {
  151.                 SetWindowPic(gSplashScreen, picH);
  152.                 // Don't show it here, since we only want to it for oapp launches!
  153.                 // ShowWindow(gSplashScreen);
  154.             }
  155.         }
  156.     }
  157. }
  158.  
  159.  
  160. /*    --------------- Standard Event Handling routines ---------------------- */
  161. #pragma segment Main
  162. void ShowAbout () {
  163.     (void) Alert ( 128, NULL );
  164.     }
  165.  
  166.  
  167. #pragma segment Main
  168. void DoMenu ( long retVal ) {
  169.     short    menuID, itemID;
  170.     Str255    itemStr;
  171.  
  172.     menuID = HiWord ( retVal );
  173.     itemID = LoWord ( retVal );
  174.     
  175.     switch ( menuID ) {
  176.         case kAppleNum:
  177.             if ( itemID == 1 )
  178.                 ShowAbout ();    /*    Show the about box */
  179.             else
  180.             {
  181.                 GetItem(GetMHandle(kAppleNum), itemID, itemStr);
  182.                 OpenDeskAcc(itemStr);
  183.             }
  184.             break;
  185.             
  186.         case kFileNum:
  187.             if ( itemID == 1 )
  188.                 SelectFile();        // call file selection userProc
  189.             else
  190.                 SendQuitToSelf();    // send self a 'quit' event
  191.             break;
  192.         
  193.         default:
  194.             break;
  195.             
  196.         }
  197.     HiliteMenu(0);        // turn it off!
  198.     }
  199.  
  200.  
  201. #pragma segment Main
  202. void DoMouseDown ( EventRecord *curEvent ) {
  203.     WindowPtr    whichWindow;
  204.     short        whichPart;
  205.  
  206.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  207.     switch ( whichPart ) {
  208.         case inMenuBar:
  209.             DoMenu ( MenuSelect ( curEvent->where ));
  210.             break;
  211.         
  212.         case inSysWindow:
  213.             SystemClick ( curEvent, whichWindow );
  214.             break;
  215.         
  216.         case inDrag:
  217.             {
  218.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  219.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  220.             }
  221.         default:
  222.             break;
  223.         }
  224.     }
  225.  
  226.  
  227. #pragma segment Main
  228. void DoKeyDown ( EventRecord *curEvent ) {
  229.     if ( curEvent->modifiers & cmdKey )
  230.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  231.     }
  232.  
  233.  
  234.  
  235. #pragma segment Main
  236. void main ( ) 
  237. {
  238.  
  239.     InitToolbox ();
  240.     if ( InitGlobals () ) {    // if we succeeding in initting self
  241.         if ( !gHasAppleEvents )
  242.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  243.         else {
  244.             InitAEVTStuff ();
  245.             SetUpMenus ();
  246.             InstallSplashScreen ();
  247.             
  248.             while ( !gDone ) {
  249.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  250.                 if ( gWasEvent ) {
  251.                     switch ( gEvent.what ) {
  252.                         case kHighLevelEvent:
  253.                             DoHighLevelEvent ( &gEvent );
  254.                             break;
  255.                             
  256.                         case mouseDown:
  257.                             DoMouseDown ( &gEvent );
  258.                             break;
  259.                             
  260.                         case keyDown:
  261.                         case autoKey:
  262.                             DoKeyDown ( &gEvent );
  263.                             break;
  264.  
  265.                         case diskEvt:
  266.                             if (HiWord(gEvent.message)) {
  267.                                 Point diskInitPt;
  268.                                 
  269.                                 diskInitPt.v = diskInitPt.h = 100;
  270.                                 DILoad();
  271.                                 DIBadMount(diskInitPt, gEvent.message);
  272.                                 DIUnload();
  273.                             }
  274.                             break;
  275.                             
  276.                         default:
  277.                             break;
  278.                     }
  279.                 }
  280.             }
  281.         }
  282.         DisposeUserGlobals();    // call the userproc to clean itself up
  283.     }
  284. }
  285.